package com.fzz.learnitservice.context;

public class UserContext {
    private static final ThreadLocal<Long> USER_HOLDER = new ThreadLocal<>();

    public static void setUserId(long userId) {
        USER_HOLDER.set(userId);
    }

    /**
     * 获取用户ID，如果ThreadLocal中为null则返回null
     * @return 用户ID，可能为null
     */
    public static Long getUserId() {
        return USER_HOLDER.get();
    }

    public static void clear() {
        USER_HOLDER.remove();
    }
}